<template>
	<view class="home">
		<!-- 轮播 -->
		<swiper indicator-dots circular autoplay>
			<swiper-item v-for="item in swipers" :key="item.id">
				<image :src="item.img"></image>
			</swiper-item>
		</swiper>
		<!-- 导航 -->
		<view class="nav">
			<view class="nav_item" v-for="(item,index) in navs" :key="index" @click="navItem(item.path)">
				<view :class="item.icon"></view>
				<text>{{item.title}}</text>
			</view>
			
		</view>
		<!-- 推荐商品区 -->
		<view class="hot_goods">
			<view class="tit">推荐商品</view>
			<good-list @goodsItemClick="goGoodsDetail" :goods="goods"></good-list>
		</view>
	</view>
</template>

<script>
	import goodsList from '../../components/good-list/good-list.vue'
	export default {
		data() {
			return {
				title: 'Hello',
				swipers:[],
				goods:[],
				navs:[
					{
						icon:'iconfont  icon-ziyuan',
						title:'又得超市',
						path:'/pages/goods/goods'
					},
					{
						icon:'iconfont  icon-guanyuwomen',
						title:'联系我们',
						path:'/pages/contact/contact'	
					},
					{
						icon:'iconfont  icon-tupian',
						title:'社区图片',
						path:'/pages/pics/pics'
					},
					{
						icon:'iconfont  icon-shipin',
						title:'推荐商品',
						path:'/pages/goods/goods'
					}
				]
				
			}
		},
		onLoad() {
			this.getLunBoPic()
			this.getHotGoodsList()
		},
		components:{
			"good-list":goodsList
		},
		methods: {
			// 获取轮播图的数据
			async getLunBoPic(){
				const res = await this.$myRequest({
					url:'/api/getlunbo'
				})
				this.swipers = res.data.message
							
			},
			// 导航点击事件
			navItem(path){
				uni.navigateTo({
					url:path
					
				})
			},
			// 商品详情
			goGoodsDetail(id){
				console.log('首页id',id)
				uni.navigateTo({
					url:'../goodsDetail/goodsDetail?id='+id
				})
			},
			// 获取热门商品列表数据
			async getHotGoodsList(){
				const res = await this.$myRequest({
					url:'/api/getgoods?pageindex=1'
				})
			this.goods = res.data.message
			}
		},
		// 触底触发事件
		onReachBottom() {
			console.log('到底了')
		},
		
	}
</script>

<style lang="scss">
	.home{
		swiper{
			width: 750rpx;
			height: 380rpx;
			image{
				height: 100%;
				width: 100%;
			}
		}
		
		.hot_goods{
			background: #eee;
			.tit{
				height: 50px;
				line-height: 50px;
				color: #b50e03;
				text-align: center;
				font-size: 40rpx;
				letter-spacing: 20px;
				margin: 10rpx auto;
			}
			
		}
		.nav{
			display: flex;
			.nav_item{
				width: 25%;
				text-align: center;
				view{
					width: 120rpx;
					height: 120rpx;
					background: #C31E00;
					border-radius: 50%;
					margin: 10px auto;
					line-height: 120rpx;
					color: #FFFFFF;
					font-size: 50rpx;
					
				}
				.icon-tupian{
					font-size: 45rpx;
				}
				text{
					font-size: 25rpx;
				}
			}
		}
		
	}
</style>
